#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
    int ans = 0, f = 0;
    char c = getchar();
    while (!isdigit(c))
        f |= c == '-', c = getchar();
    while (isdigit(c))
        ans = (ans << 3) + (ans << 1) + c - 48, c = getchar();
    return f ? -ans : ans;
}
void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar(48 + x % 10);
}
const int N = 5e5 + 5;
int n, m, ans, s[N];
int a[N], l[N], r[N];
inline bool special1()
{
    if (n > 20 || m > 20)
        return 0;
    auto sum = [&](int l, int r)
    { return s[r] - s[l - 1]; };
    auto check = [&]()
    {
        for (int j = 1; j <= m; ++j)
            if (!sum(l[j], r[j]))
                return 0;
        return 1;
    };
    for (int i = 1; i < (1 << n); ++i)
    {
        int res = 0;
        for (int j = 1; j <= n; ++j)
        {
            s[j] = s[j - 1] + (i >> j - 1 & 1);
            if (i >> j - 1 & 1)
                res += a[j];
        }
        if (check())
            ans = min(ans, res);
    }
    write(ans);
    return 1;
}
inline bool special2()
{
    for (int i = 1; i <= m; ++i)
        ++s[l[i]], --s[r[i] + 1];
    for (int i = 1; i <= n; ++i)
        if ((s[i] += s[i - 1]) > 1)
            return 0;
    for (int i = 1; i <= m; ++i)
    {
        int res = 1e9;
        for (int j = l[i]; j <= r[i]; ++j)
            res = min(res, a[j]);
        ans += res;
    }
    write(ans);
    return 1;
}
signed main()
{
    freopen("gonna.in", "r", stdin);
    freopen("gonna.out", "w", stdout);
    n = read();
    for (int i = 1; i <= n; ++i)
        a[i] = read();
    m = read();
    for (int i = 1; i <= m; ++i)
        l[i] = read(), r[i] = read();
    ans = 1e9;
    if (special1() || special2())
        return 0;
    return 111;
}